<?php
    class APaymentTotal extends CActiveRecord{
        public static function model($className = __CLASS__) {
            return parent::model ( $className );
        }
        public function getDataSmsByMonthAndYear($month,$year){
            $condition="";
            if(isset($month)){
                $condition.=" AND month=".$month;
            }
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price) as count,`day`,`month`,`year`,`price`,`serviceNumber` FROM c_sms_log WHERE 1 AND status=1 ".$condition." GROUP BY day, price, serviceNumber";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
        public function getDataCardByMonthAndYear($month,$year){
            $condition="";
            if(isset($month)){
                $condition.=" AND month=".$month;
            }
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price) as count,`day`,`month`,`year`,`price` FROM c_card_log WHERE 1 AND status=1 ".$condition." GROUP BY day, price";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
        public function getDataChargingByMonthAndYear($month,$year){
            $condition="";
            if(isset($month)){
                $condition.=" AND month=".$month;
            }
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price_telco) as count, price_telco,`day`,`month`,`year` FROM c_wapcharging_log WHERE 1 AND status=1 ".$condition." GROUP BY day,price_telco";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
        public function getDataSmsByYear($year){
            $condition="";
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price) as count,`month`,`year`,`price`,`serviceNumber` FROM c_sms_log WHERE 1 AND status=1 ".$condition." GROUP BY month, price, serviceNumber";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
        public function getDataCardByYear($year){
            $condition="";
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price) as count,`month`,`year`,`price` FROM c_card_log WHERE 1 AND status=1 ".$condition." GROUP BY month, price";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
        public function getDataChargingByYear($year){
            $condition="";
            if(isset($year)){
                $condition.=" AND year=".$year;
            }
            $sql="SELECT count(price_telco) as count, price_telco,`month`,`year` FROM c_wapcharging_log WHERE 1 AND status=1 ".$condition." GROUP BY month, price_telco";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            return $rows;
        }
    }
?>
